//
//  LHQDestinationDetailphotoShowViewController.m
//  God_is_a_Girl
//
//  Created by dllo on 15/9/25.
//  Copyright (c) 2015年 呸. All rights reserved.
//

#import "LHQDestinationDetailphotoShowViewController.h"
#import "LHQDestinationDetailPhotoFilmViewController.h"
#define WIDTH ([UIScreen mainScreen].bounds.size.width/375)
#define HEIGH ([UIScreen mainScreen].bounds.size.height/667)
@interface LHQDestinationDetailphotoShowViewController () <UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,retain) NSMutableArray  *arr;

@property (nonatomic,retain) UITableView  *tableView;

@property (nonatomic,retain) UICollectionViewFlowLayout  *flowLayout;

@property (nonatomic,retain) UICollectionView  *collection;

@end

@implementation LHQDestinationDetailphotoShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self  datahandel];

}

-(void)collectionViewSubView
{
    //创建瀑布流
    self.flowLayout = [[UICollectionViewFlowLayout  alloc] init];
    //创建对象
    self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:self.flowLayout];
    //方块大小
    self.flowLayout.itemSize = CGSizeMake(335*WIDTH/3, 100);
    
    
    //最小列间距
    self.flowLayout.minimumInteritemSpacing = 10 ;
    //最小行间距
    self.flowLayout.minimumLineSpacing = 10 ;
    //设置item据四边的间距
    self.flowLayout.sectionInset = UIEdgeInsetsMake(10 , 10 , 10 , 10);
    [self.view  addSubview:self.collection];
    self.collection.backgroundColor = [UIColor whiteColor];
    
    //两个协议
    self.collection.delegate = self;
    self.collection.dataSource = self;
    
    //collectionViewcell 必须提前注册
    [self.collection registerClass:[LHQDestinationDetailPhotoShowCollectionViewCell  class] forCellWithReuseIdentifier:@"reuse"];
    
}
-(void)datahandel
{
    self.arr  = [NSMutableArray array];
    AFHTTPRequestOperationManager  *manager = [AFHTTPRequestOperationManager   manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet  setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];//支持所有接口类型
    
    NSString *str = [NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/%@/%@/photos/?start=0&count=21&gallery_mode=true",self.type,self.idStr];//
    
    [manager   GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        self.arr = [responseObject  objectForKey:@"items"];
      
        [self.collection  reloadData];
        [self  collectionViewSubView];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
    
}
//tableView必须实现方法
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
    
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.arr.count ;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary  *dic = [self.arr objectAtIndex:indexPath.row];
    LHQDestinationDetailPhotoShow  *model = [[LHQDestinationDetailPhotoShow  alloc] init];
    [model  setValuesForKeysWithDictionary:dic];
    LHQDestinationDetailPhotoShowCollectionViewCell  *cell = [collectionView  dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.model = model;
    return cell;
    
}
//调转界面属性传值
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    LHQDestinationDetailPhotoFilmViewController  *film = [[ LHQDestinationDetailPhotoFilmViewController  alloc] init];
    film.idStr = self.idStr;
    film.type = self.type;
    [self.navigationController   pushViewController:film animated:YES];
    
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
